Why does my 3D model not translate the way I expect? [closed]
Posted
by
ChocoMan
on Game Development
See other posts from Game Development
or by ChocoMan
Published on 2012-09-06T04:00:23Z
Indexed on
2012/10/16
23:23 UTC
Read the original article
Hit count: 308
In my first image, my model displays correctly:
But when I move the model's position along the Z-axis (forward) I get this, yet the Y-axis doesnt change. An if I keep going, the model disappears into the ground:
Any suggestions as to how I can get the model to translate properly visually? Here is how Im calling the model and the terrain in draw()
:
cameraPosition = new Vector3(camX, camY, camZ);
// Copy any parent transforms.
Matrix[] transforms = new Matrix[mShockwave.Bones.Count];
mShockwave.CopyAbsoluteBoneTransformsTo(transforms);
Matrix[] ttransforms = new Matrix[terrain.Bones.Count];
terrain.CopyAbsoluteBoneTransformsTo(ttransforms);
// Draw the model. A model can have multiple meshes, so loop.
foreach (ModelMesh mesh in mShockwave.Meshes)
{
// This is where the mesh orientation is set, as well
// as our camera and projection.
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;
effect.World = transforms[mesh.ParentBone.Index] *
Matrix.CreateRotationY(modelRotation)
* Matrix.CreateTranslation(modelPosition);
// Looking at the model (picture shouldnt change other than rotation)
effect.View = Matrix.CreateLookAt(cameraPosition,
modelPosition, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45.0f), aspectRatio,
1.0f, 10000.0f);
effect.TextureEnabled = true;
}
// Draw the mesh, using the effects set above.
prepare3d();
mesh.Draw();
}
//Terrain test
foreach (ModelMesh meshT in terrain.Meshes)
{
foreach (BasicEffect effect in meshT.Effects)
{
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;
effect.World = ttransforms[meshT.ParentBone.Index] *
Matrix.CreateRotationY(0)
* Matrix.CreateTranslation(terrainPosition);
// Looking at the model (picture shouldnt change other than rotation)
effect.View = Matrix.CreateLookAt(cameraPosition,
terrainPosition, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45.0f), aspectRatio,
1.0f, 10000.0f);
effect.TextureEnabled = true;
}
// Draw the mesh, using the effects set above.
prepare3d();
meshT.Draw();
DrawText();
}
base.Draw(gameTime);
}
I'm suspecting that there may be something wrong with how I'm handling my camera. The model rotates fine on its Y-axis.
© Game Development or respective owner